﻿using System;
using System.Windows.Forms;
using System.Resources;
using BS.FormControls;

namespace CssCommonLibrary
{
    public sealed class CSSExtendedList : UserControl
    {
        ResourceManager resx;

        public event ItemCheckEventHandler OnCssChecked;

        public CssNodeList DataSource
        {
            set
            {
                cbList_CSS.InitialDataSource = value;
                cbList_CSS.BindData();
            }
        }

        public string Value
        {
            get
            {
                return cbList_CSS.CheckedNodes.ToString();
            }
        }

        private string InitialFilterText
        {
            get
            {
                return tb_Filter.Text = resx.GetObject("FilterText") as string;
            }
        }

        public CSSExtendedList()
        {
            InitializeComponent();
            resx = new ResourceManager(this.GetType());
            tb_Filter.Text = InitialFilterText;
        }

        private SearchTextBox tb_Filter;
        private System.ComponentModel.IContainer components = null;
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code
        private void InitializeComponent()
        {
            this.cbList_CSS = new CssCheckList();
            this.tb_Filter = new SearchTextBox();
            this.SuspendLayout();
            // 
            // cbList_CSS
            // 
            this.cbList_CSS.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.cbList_CSS.FormattingEnabled = true;
            this.cbList_CSS.HorizontalScrollbar = true;
            this.cbList_CSS.InitialDataSource = null;
            this.cbList_CSS.Location = new System.Drawing.Point(0, 25);
            this.cbList_CSS.Margin = new System.Windows.Forms.Padding(0);
            this.cbList_CSS.Name = "cbList_CSS";
            this.cbList_CSS.Size = new System.Drawing.Size(400, 394);
            this.cbList_CSS.TabIndex = 1;
            this.cbList_CSS.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.cbList_CSS_ItemCheck);
            // 
            // tb_Filter
            // 
            this.tb_Filter.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.tb_Filter.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Italic);
            this.tb_Filter.Location = new System.Drawing.Point(0, 0);
            this.tb_Filter.Name = "tb_Filter";
            this.tb_Filter.Size = new System.Drawing.Size(400, 20);
            this.tb_Filter.TabIndex = 2;
            this.tb_Filter.Text = "please enter your search text.";
            // 
            // CSSExtendedList
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.tb_Filter);
            this.Controls.Add(this.cbList_CSS);
            this.Margin = new System.Windows.Forms.Padding(0);
            this.Name = "CSSExtendedList";
            this.Size = new System.Drawing.Size(400, 424);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private CssCheckList cbList_CSS;

        private void tb_Filter_TextChanged(object sender, EventArgs e)
        {
            if (tb_Filter.Text != InitialFilterText)
                cbList_CSS.Filter(tb_Filter.Text);
        }

        private void cbList_CSS_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (OnCssChecked != null)
                OnCssChecked(sender, e);
        }
    }

}
